package com.iplay.thezen.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Date;

/**
 * @author dangwu
 * @since 2021/9/4 3:59 下午
 */
public class TestClient {
    //    public static void main(String[] args) {
//        IGamePlayer player = new GamePlayer("张三");
//        InvocationHandler handler = new GamePlayIH(player);
//        System.out.println("开始时间是：" + new Date());
//        ClassLoader classLoader = player.getClass().getClassLoader();
//        IGamePlayer proxy = (IGamePlayer) Proxy.newProxyInstance(classLoader, player.getClass().getInterfaces(), handler);
//        proxy.login("zhangsan", "pwd");
//        proxy.killBoss();
//        proxy.upgrade();
//        System.out.println("结束时间是：" + new Date());
//    }
    public static void main(String[] args) {
//        //定义一个主题
//        Subject subject = new RealSubject();
//        //定义一个handler
//        InvocationHandler handler = new GamePlayIH(subject);
//        //定义主题的代理
//        Subject proxy = DynamicProxy.newProxyInstance(subject.getClass().getClassLoader(), subject.getClass().getInterfaces(), handler);
//        proxy.request();


//        IGamePlayer player = new GamePlayer("张三");
//        InvocationHandler handler = new GamePlayIH(player);
//        System.out.println("开始时间是：" + new Date());
//        IGamePlayer proxy = (IGamePlayer) Proxy.newProxyInstance(player.getClass().getClassLoader(), player.getClass().getInterfaces(), handler);
//        proxy.login("zhangsan", "pwd");
//        proxy.killBoss();
//        proxy.upgrade();
//        System.out.println("结束时间是：" + new Date());

        AbstractClazz clazz = new RealClazz();
        InvocationHandler handler = new GamePlayIH(clazz);
        AbstractClazz proxy = (AbstractClazz) Proxy.newProxyInstance(clazz.getClass().getClassLoader(), clazz.getClass().getInterfaces(), handler);
        proxy.request();
    }

}
